<?php
/**
 * 收支记录导出
 * author itholiday@126.com
 */

if (isset($_GET['ids']) && !empty($_GET['ids'])) {
    $ids = addslashes($_GET['ids']);
    $where = "A.id in ($ids)";
} else {
    $where = 'A.id>0 ';
}


$user_id = isset($_GPC['user_id']) && !empty($_GPC['user_id']) ? input('user_id') : '';
$mobile = isset($_GPC['mobile']) && !empty($_GPC['mobile']) ? input('mobile') : '';
$start_time = isset($_GPC['start_time']) && !empty($_GPC['start_time']) ? strtotime($_GPC['start_time']) : '';
$end_time = isset($_GPC['end_time']) && !empty($_GPC['end_time']) ? strtotime($_GPC['end_time']) : '';

if (!empty($mobile)) {
    $where .= " and u.mobile like '%$mobile%' ";
}
if (!empty($user_id)) {
    $where .= " and A.user_id like '%$user_id%' ";
}
if (!empty($start_time) && !empty($end_time)) {
    $where .= " and A.create_time>=$start_time and A.create_time<=$end_time ";
} else {
    if (!empty($start_time)) {
        $where .= " and A.create_time>=$start_time ";
    }
    if (!empty($end_time)) {
        $where .= " and A.create_time<=$end_time ";
    }
}


$field = "A.id,u.truename,u.mobile,u.alipay_name,u.alipay_account,A.type,A.change,A.balance,A.create_time,A.remark";
$sql = " select $field from ims_yq_haircircle_user_money_log A join ims_yq_haircircle_users u on A.user_id = u.id where $where order by A.id desc ";
$data = pdo_fetchall($sql);


if (empty($data)) $data = array();

foreach ($data as $k => $v) {
    switch ($v['type']) {
        case   -1:
            $data[$k]['type'] = '提现';
            break;
        case  1:
            $data[$k]['type'] = '完成任务';
            break;
        case  2:
            $data[$k]['type'] = '分销返佣';
            break;
        case  3:
            $data[$k]['type'] = "升级返佣";
            break;
    }
    $data[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
}

$fileName = '收支记录_' . date('Y-m-d H i s');
$header = array(
    'ID', '用户名', '手机号码', '支付宝姓名', '类型', '支付宝账号', '改变金额', '更改后的金额', '时间', '备注'
);

exportExcel($data, $fileName, $header, '收支记录');